<template>
	<view>
		<htmlHead :indexdata="indexdata"></htmlHead>
		<view class="bodyt2">
			<view class="bodyt2-1">
				<el-breadcrumb separator-class="el-icon-arrow-right">
					<i class="el-icon-location-outline" style="float: inline-start;font-size: 20px;">当前位置:</i>
				  <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
				  <el-breadcrumb-item>检索文章</el-breadcrumb-item>
				</el-breadcrumb>
			</view>
			<view class="bodyt2-2">
<!-- 				<view class="bodyt2-2-1">
					<view class="bodyt2-2-1-1">
						<view class="zcfglist">
							<p @click="gotofg('xwzx')"><i class="el-icon-caret-right"></i>新闻资讯</p>
							<p @click="gotofg('llyj')"><i class="el-icon-caret-right"></i>理论研究</p>
							<p @click="gotofg('mxrw')"><i class="el-icon-caret-right"></i>民校人物</p>
							<p @click="gotofg('hyfc')"><i class="el-icon-caret-right"></i>会员风采</p>
							<p @click="gotofg('xhwj')"><i class="el-icon-caret-right"></i>协会文件</p>
							<p @click="gotofg('zlxz')"><i class="el-icon-caret-right"></i>资料下载</p>
						</view>
					</view>
				</view> -->
				<view class="bodyt2-2-2">
					<view class="bodyt2-2-2-1" style="font-size: 20px;align-content: center;justify-content: center;align-items: center;">
						<span style="color: #ba1c1b;font-size: x-large;position: relative;left: 10px;">检索文章</span>
					</view>
					<view class="bodyt2-2-2-2">
						<uParse v-show="!temps" style="word-break:break-all" :content="editor" @preview="preview" @navigate="navigate"/>
						<uni-list  v-show="temps">
							<uni-list-item class="unilistitem" clickable
								v-for="(item, index) in pageData"  @click="xsnr(item)" :key="index"
								:title="item.title.length > 45?item.title.substring(0, 45)+'...':item.title.substring(0, 45)" 
								:rightText="vk.pubfn.timeFormat(item._add_time,'yyyy-MM-dd hh:mm:ss')"
								 />
						</uni-list>
					</view>
					<view class="bodyt2-2-2-3"  v-show="temps">
						<uni-pagination style="position: relative;left: 290px;top: 10px;" :total="listCont" title="标题文字" @change="change"/>
					</view>
				</view>
			</view>
		</view>
		<htmlFoot></htmlFoot>
	</view>
</template>
<script>
	import htmlHead from "@/components/html/html-head.vue";
	import htmlFoot from "@/components/html/html-foot.vue";
	import uParse from "@/components/feng-parse/parse.vue"
	var vk = uni.vk;
	export default {
		components: {
			htmlHead,
			htmlFoot,
			uParse
		},
		data() {
			// 页面数据变量
			return {
				editor:'',
				temps:true,
				indexdata:0,
				temptilet:'',
				activeName: 'first',
				options:{},
				listCont:0,
				listtemp:[],
				pageData: [],
				xwzxList:[]
			}
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		async onLoad(options = {}) {
			vk = uni.vk;
			this.options = options;
			//this.pdtemptilet()
			//await this.getDatanows()
			//this.pageData = this.paginate(this.listtemp, 10, 1)
			//await this.getNewsTjcxList()
			
			// if(this.options.tempss){
			// 	let item = {}
			// 	item._id = this.options.idd
			// 	item.nrtype = [this.options.tempdata]
			// 	this.xsnr(item)
			// }else{
			// 	await this.getDatanows()
			// 	this.pageData = this.paginate(this.listtemp, 10, 1)
			// }
			//console.log(this.options.tempdata)
			await this.getDatanows()
			this.pageData = this.paginate(this.listtemp, 10, 1)
			
			
		},
		// 函数
		methods: {
			navigate(href, e) {
				this.downloadFile(href,'unknown.file')
			},
			downloadFile(url, filename = 'unknown.file') {  
				// 使用方法：  
				//downloadFile('path/to/your/file.pdf', 'myfile.pdf');
			    const a = document.createElement('a');  
			    a.href = url;  
			    a.download = filename;  
			    a.style.display = 'none';  
			    document.body.appendChild(a);  
			    a.click();  
			    document.body.removeChild(a);  
			},
			xsnr(item){
				this.temps = false
				this.editor = ''
				
				if(item.nrtype.includes('xwzx')){
					this.temptilet = '新闻资讯'
				}else if(item.nrtype.includes('llyj')){
					this.temptilet = '理论研究'
				}else if(item.nrtype.includes('mxrw')){
					this.temptilet = '民校人物'
				}else if(item.nrtype.includes('hyfc')){
					this.temptilet = '会员风采'
				}else if(item.nrtype.includes('xhwj')){
					this.temptilet = '协会文件'
				}else if(item.nrtype.includes('zlxz')){
					this.temptilet = '资料下载'
				}else if(item.nrtype.includes('sytw')){
					this.temptilet = '首页图文'
				}
				
				return vk.callFunction({
				  url: 'client/hymbjy/pub/news.getNewsById',
				  data:{
				    tempid:item._id
				  }
				}).then((data) => {
				  this.editor = data.info.editor
				}).catch((err) => {
				  
				});
			},
			async gotofg(taipp){
				this.options.tempdata = taipp

				this.listCont = 0
				this.listtemp = []
				await this.getDatanows()
				this.pageData = this.paginate(this.listtemp, 10, 1)
				this.temps = true
				if(this.options.tempdata == 'xwzx'){
					this.temptilet = '新闻资讯'
					this.temps = true
				}else if(this.options.tempdata == 'llyj'){
					this.temptilet = '理论研究'
					this.temps = true
				}else if(this.options.tempdata == 'mxrw'){
					this.temptilet = '民校人物'
					this.temps = true
				}else if(this.options.tempdata == 'hyfc'){
					this.temptilet = '会员风采'
					this.temps = true
				}else if(this.options.tempdata == 'xhwj'){
					this.temptilet = '协会文件'
					this.temps = true
				}else if(this.options.tempdata == 'zlxz'){
					this.temptilet = '资料下载'
					this.temps = true
				}else if(this.options.tempdata == 'sytw'){
					this.temptilet = '首页图文'
					this.temps = true
				}

			},
			goDetails(item){
				vk.navigateTo('/pages/modo/details?idd='+item._id);
			},
			pdtemptilet(){
				if(this.options.tempdata == 'xwzx'){
					this.temptilet = '新闻资讯'
				}else if(this.options.tempdata == 'zcfg'){
					this.temptilet = '政策法规'
				}else if(this.options.tempdata == 'llyj'){
					this.temptilet = '理论研究'
				}else if(this.options.tempdata == 'xhwj'){
					this.temptilet = '协会文件'
				}else if(this.options.tempdata == 'xhhd'){
					this.temptilet = '协会活动'
				}else if(this.options.tempdata == 'mxrw'){
					this.temptilet = '民校人物'
				}else if(this.options.tempdata == 'djgz'){
					this.temptilet = '党建工作'
				}else if(this.options.tempdata == 'hyfc'){
					this.temptilet = '会员风采'
				}else if(this.options.tempdata == 'zlxz'){
					this.temptilet = '资料下载'
				}
			},
			change(e) {
				this.pageData = this.paginate(this.listtemp, 10, e.current);  
			},
			getNewsTjcxList(){
				return vk.callFunction({
				  url: 'client/hymbjy/pub/news.getNewsTjcxList',
				  data:{
					  tjcx:['xwzx']
				  }
				}).then((data) => {
					this.xwzxList = data.list.slice(0, 7); 
				}).catch((err) => {
				  
				});
			},
			getDatanows(){
				//console.log(this.options.message)
				return vk.callFunction({
				  url: 'client/hymbjy/pub/news.getNewsListWzss',
				  data:{
					  title:this.options.message
				  }
				}).then((data) => {
					this.listCont = data.list.length
					this.listtemp = data.list
				}).catch((err) => {
				  
				});
			},
			paginate(items, pageSize, pageNum) {  
				//var pageSize = 10; // 每页10个项目  
				//var pageNum = 2;   // 请求第2页  
				
			    // 确保页码是整数并且不小于1  
			    pageNum = Math.max(1, Math.floor(pageNum));  
			  
			    // 计算起始索引  
			    var startIndex = (pageNum - 1) * pageSize;  
			  
			    // 确保起始索引不会超过数组长度  
			    startIndex = Math.min(startIndex, items.length);  
			  
			    // 计算结束索引  
			    var endIndex = startIndex + pageSize;  
			  
			    // 如果结束索引超过数组长度，则将其设置为数组长度  
			    endIndex = Math.min(endIndex, items.length);  
			  
			    // 返回指定页的数据  
			    return items.slice(startIndex, endIndex);  
			}  
		}
	}
</script>
<style lang="scss" scoped>
	
	.bodyt2 {
		margin: auto;
		background-color: #f5f5f5;
		width: 2000px;
		min-height: 640px;
		display: flex;
		flex-direction: column;
		align-content: center;
		justify-content: center;
		align-items: center;
		flex-wrap: nowrap;
	}
	.bodyt2-1{
		margin: auto;
		width: 1200px;
		height: 40px;
		display: flex;  
		  //justify-content: center; /* 水平居中 */
		  align-items: center; /* 垂直居中 */  
	}
	.bodyt2-2{
		width: 1200px;
		min-height: 560px;
		position: relative;
		    display: flex;
		    flex-direction: row;
		    flex-wrap: nowrap;
		    align-content: flex-start;
		    justify-content: flex-start;
		    align-items: flex-start;
	}
	.bodyt2-3{
		margin: auto;
		width: 1000px;
		height: 20px;
		background-color: coral;
	}
	.el-breadcrumb {
	    font-size: 18px;
	    line-height: 1;
	}
	
	.bodyt2-2-1{
		width: 240px;
		height: 560px;
	}
	
	.bodyt2-2-1-1{
		width: 240px;
		height: 560px;
		background-color: #e6e6e6;
		border-top: 5px solid #9f9f9f;
	}
	.bodyt2-2-1-2{
		width: 240px;
		height: 280px;
		margin-top: 5px;
		border: 1px solid #e6e6e6;
	}
	.bodyt2-2-2{
		width: 960px;
		min-height: 560px;
		margin-left: 40px;
	}
	.bodyt2-2-2-1{
		width: 960px;
		height: 40px;
		border-left: 5px solid #ba1c1b;
	}
	.bodyt2-2-2-2{
		width: 960px;
		min-height: 470px;
	}
	.bodyt2-2-2-3{
		width: 960px;
		height: 50px;
	}
	.zcfglist{
    width: 170px;
    height: 100%;
    position: relative;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
	}
	.zcfglist p{
		cursor: pointer;
		border-bottom: 1px solid #9f9f9f;
		margin: 10px 10px;
		font-weight: 600;
		font-size: 20px;
		line-height: 2.0;
	}
	.xwzxList{
		line-height: 2.0;
		margin: 0px 20px;
		cursor: pointer;
	}
	.xwzxList:hover{
		color: #ba1c1b;
	}
	.unilistitem{
		
	}
	.unilistitem:hover{
		color: #ba1c1b;
	}
</style>